package dongfeng.action;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.Property;
import weaver.soa.workflow.request.RequestInfo;

/**
 * Created by frank and Huangwm on 2018-10-11.
 * 新建企业信息
 * 部署到正式系统
 *
 */
public class AddwriteContacts implements Action{
	private static Log log = LogFactory.getLog(AddwriteContacts.class);
	public String execute(RequestInfo request) {
		log.info("=======================Start.");
		if(request != null) {
				//获取主表属性对象
				Property[] property=request.getMainTableInfo().getProperty();
				String qymc = "";	//企业名称
				String qyjc = "";	//企业简称
				String qyfr = "";	//企业法人
				String yddh = "";	//移动电话
				String qyfrhx = "";	//企业法人id
				String bmhx = "";	//企业部门id
				for(int i = 0; i < property.length; i++) {
					if("qymc".equals(property[i].getName())){
						qymc = Util.null2String(property[i].getValue());
					}
					if("qyjc".equals(property[i].getName())){
						qyjc = Util.null2String(property[i].getValue());
					}
					if("qyfr".equals(property[i].getName())){
						qyfr = Util.null2String(property[i].getValue());
					}
					if("yddh".equals(property[i].getName())){
						yddh = Util.null2String(property[i].getValue());
					}
					if("qyfrhx".equals(property[i].getName())){
						qyfrhx = Util.null2String(property[i].getValue());
					}
					if("bmhx".equals(property[i].getName())){
						bmhx = Util.null2String(property[i].getValue());
					}
				}
				log.info("企业名称="+qymc+"，企业简称="+qyjc+"，企业法人="+qyfr+"，" +
						"移动电话="+yddh+",企业法人id="+qyfrhx+",企业部门id="+bmhx);
				
				String sql="select * from uf_EnterpriseInfo where qymc='"+qymc+"' and qyjc='"+qyjc
						+"' and qyfr='"+qyfr+"' and yddh='"+yddh+"' and bmhx="+bmhx+" and qyfrhx="+qyfrhx;
				RecordSet rs =new RecordSet();
				log.info("查询新建企业的uf_EnterpriseInfo的记录id："+sql);
				rs.execute(sql);
				String qymcid="";
				if (rs.next()) {
					qymcid=rs.getString("id");
				}
				
				RecordSet rs2 =new RecordSet();
				String sql2="update uf_EPContacts set qymcid="+qymcid+" where qymc='"+bmhx+"' and lxr='"
						+qyfr+"' and lxdh='"+yddh+"' and qyfr=lxrhx and qyfr="+qyfrhx;
				log.info("更新uf_EPContacts表qymcid："+sql2);
				rs2.execute(sql2);
				 
			log.info("=======================End.");
		
		}
		//return Action.SUCCESS;
		return Action.SUCCESS;
	}
}
